<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();


echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/inc/trim.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/homePro.js?v='. OT_VERSION .'"></script>
');


switch ($mudi){
	case 'add':
		$MB->IsSecMenuRight('alertBack',9,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$MB->IsSecMenuRight('alertBack',10,$dataType);
		AddOrRev();
		break;

	case 'manage':
		$MB->IsSecMenuRight('alertBack',51,$dataType);
		manage();
		break;

	default:
		die('err');
}

$skin->WebBottom();

$MB->Close();
$DB->Close();





// 新增、修改信息
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$backURL		= OT::GetStr('backURL');
	$dataID			= OT::GetInt('dataID');

	if ($mudi=='rev'){
		$revexe=$DB->query('select * from '. OT_dbPref .'homePro where HP_ID='. $dataID);
			if (! $row = $revexe->fetch()){
				JS::AlertBackEnd('无该记录！');		
			}
		$HP_ID		= $row['HP_ID'];
		$HP_type	= $row['HP_type'];
		$HP_theme	= $row['HP_theme'];
		$HP_img		= $row['HP_img'];
		$HP_desc	= $row['HP_desc'];
		$HP_price1	= $row['HP_price1'];
		$HP_price2	= $row['HP_price2'];
		$HP_btnName	= $row['HP_btnName'];
		$HP_url		= $row['HP_url'];
		$HP_rank	= $row['HP_rank'];
		$HP_state	= $row['HP_state'];
		$HP_wapState= $row['HP_wapState'];

		$mudiCN = '修改';
		$submitCN = '修 改';
	}else{
		if ($dataID>0){
			$revexe=$DB->query('select * from '. OT_dbPref .'homePro where HP_ID='. $dataID);
			if ($row = $revexe->fetch()){
				$HP_type	= $row['HP_type'];
				$HP_theme	= $row['HP_theme'];
				$HP_img		= $row['HP_img'];
				$HP_desc	= $row['HP_desc'];
				$HP_price1	= $row['HP_price1'];
				$HP_price2	= $row['HP_price2'];
				$HP_btnName	= $row['HP_btnName'];
				$HP_rank	= $row['HP_rank'];
				$HP_state	= $row['HP_state'];
				$HP_wapState= $row['HP_wapState'];
			}
			$dataID = 0;
		}else{
			$HP_ID			= 0;
			$HP_type		= 'home';
			$HP_theme		= '';
			$HP_img			= '';
			$HP_desc		= '';
			$HP_price1		= '';
			$HP_price2		= '';
			$HP_btnName		= '查看详情';
			$HP_url			= 'http://';
			$HP_state		= 1;
			$HP_wapState	= 1;
		}
		$HP_rank		= intval($DB->GetOne('select max(HP_rank) from '. OT_dbPref .'homePro')) + 10;

		$mudiCN = '新增';
		$submitCN = '新 增';
	}

	if ($mudi=='rev'){
		echo('<div onclick="history.back();" class="font2_1 padd8 pointer">&lt;&lt;&ensp;【返回上级】</div>');
	}

	echo('
	<form id="dealForm" name="dealForm" method="post" action="homePro_deal.php?mudi='. $mudi .'&nohrefStr=close" onsubmit="return CheckForm()">
	<input type="hidden" id="dataID" name="dataID" value="'. $dataID .'" />
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataMode" name="dataMode" value="'. $dataMode .'" />
	<input type="hidden" id="dataModeStr" name="dataModeStr" value="'. $dataModeStr .'" />
	'. Area::BackUrlInput($backURL) .'

	<table cellpadding="0" cellspacing="0" summary="" class="padd5td">
	<tr><td class="tabLeftWidth"></td><td></td></tr>
	<tr>
		<td align="right">'. Skin::RedSign() .'产品名称：</td>
		<td align="left">
			<input type="text" id="theme" name="theme" size="50" style="width:380px;" value="'. Str::MoreReplace($HP_theme,'input') .'" />
		</td>
	</tr>
	<tr>
		<td align="right">'. Skin::RedSign() .'产品图标：</td>
		<td align="left" class="selectImg">
			<label>
			<select id="img" name="img">
			<!-- <option value="">上传图片</option> -->
			');
			for ($i=1; $i<=30; $i++){
				if ($i <= 8){
					echo('<option value="'. $i .'" '. Is::Selected($HP_img,$i) .'>图标'. $i .'</option>');
				}else{
					echo('<option value="'. $i .'" '. Is::Selected($HP_img,$i) .'>图标'. $i .'(自定义)</option>');
				}
			}
			echo('
			</select>
			<span><img src="temp/idcHomePro.png" style="display:none;" /></span>
			</label>
			<span style="color:red;">（自定义图标放到 inc_img\idc\ 目录下，命名：数字.png）</span>
		</td>
	</tr>
	<tr>
		<td align="right" valign="top" class="font1_2d" style="padding-top:6px;">说明：</td>
		<td align="left"><textarea id="desc" name="desc" cols="40" rows="4" style="width:510px;height:80px;" class="text" onclick=\'LoadEditor("desc",510,80,"|miniMenu|");\' title="点击开启编辑器模式">'. Str::MoreReplace($HP_desc,'textarea') .'</textarea></td>
	</tr>
	<tr>
		<td align="right">价格左侧：</td>
		<td align="left">
			<input type="text" id="price1" name="price1" size="50" style="width:520px;" value="'. $HP_price1 .'" />
		</td>
	</tr>
	<tr>
		<td align="right">价格右侧：</td>
		<td align="left">
			<input type="text" id="price2" name="price2" size="50" style="width:520px;" value="'. $HP_price2 .'" />
		</td>
	</tr>
	<tr>
		<td align="right">按钮名称：</td>
		<td align="left">
			<input type="text" id="btnName" name="btnName" size="50" style="width:520px;" value="'. $HP_btnName .'" />
		</td>
	</tr>
	<tr>
		<td align="right">按钮网址：</td>
		<td align="left">
			<input type="text" id="url" name="url" size="50" style="width:520px;" value="'. $HP_url .'" />
		</td>
	</tr>
	<tr>
		<td align="right">排序：</td>
		<td align="left"><input type="text" id="rank" name="rank" size="50" style="width:30px;" value="'. $HP_rank .'" /></td>
	</tr>
	<tr>
		<td align="right">电脑版状态：</td>
		<td align="left">
			<label><input type="radio" name="state" value="1" '. Is::Checked($HP_state,1) .' />显示</label>&ensp;&ensp;
			<label><input type="radio" name="state" value="0" '. Is::Checked($HP_state,0) .' />隐藏</label>&ensp;&ensp;
		</td>
	</tr>
	<tr>
		<td align="right">手机版状态：</td>
		<td align="left">
			<label><input type="radio" name="wapState" value="1" '. Is::Checked($HP_wapState,1) .' />显示</label>&ensp;&ensp;
			<label><input type="radio" name="wapState" value="0" '. Is::Checked($HP_wapState,0) .' />隐藏</label>&ensp;&ensp;
		</td>
	</tr>
	</table>

	<table style="height:16px;" cellpadding="0" cellspacing="0" summary=""><tr><td></td></tr></table>

	<center><input type="image" src="'. AdmTpl::ImgSrc('button_'. $mudi) .'" /></center>

	</form>
	');
}



// 管理
function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');

	$refTheme		= OT::GetRegExpStr('refTheme','sql');
	$refDesc		= OT::GetRegExpStr('refDesc','sql');
	$refState		= OT::GetInt('refState',-1);
	$refWapState	= OT::GetInt('refWapState',-1);

	$SQLstr = 'select * from '. OT_dbPref .'homePro where 1=1';

	if ($refState > -1){ $SQLstr .= ' and HP_state='. $refState; }
	if ($refWapState > -1){ $SQLstr .= ' and HP_wapState='. $refWapState; }
	if ($refTheme != ''){ $SQLstr .= " and HP_theme like '%". $DB->ForStr($refTheme,false) ."%'"; }
	if ($refDesc != ''){ $SQLstr .= " and HP_desc like '%". $DB->ForStr($refDesc,false) ."%'"; }

	$orderName = OT::ListDefVal(OT::GetStr('orderName'), 'theme|state|wapState', 'rank');
	$orderSort = OT::ListDefVal(OT::GetStr('orderSort'), 'ASC', 'DESC');

	echo('
	<div class="padd5">
		<input type="button" value="新增'. $dataTypeCN .'" onclick=\'document.location.href="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&backURL="+ encodeURIComponent(document.location.href)\' />&ensp;&ensp;
	</div>
	');

	/*
	$skin->TableTop('share_refer.gif','',$dataTypeCN .'查询');
		echo('
		<form id="refForm" name="refForm" method="get" action="">
		<input type="hidden" name="mudi" value="'. $mudi .'" />
		<input type="hidden" name="dataMode" value="'. $dataMode .'" />
		<input type="hidden" name="dataModeStr" value="'. $dataModeStr .'" />
		<input type="hidden" name="dataType" value="'. $dataType .'" />
		<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />

		<table width="98%" align="center" border="0" cellSpacing="0" cellPadding="0" summary="" class="padd5">
		<tr>
			<td style="width:30%;">
				产品名称：<input type="text" name="refTheme" size="20" style="width:175px;" value="'. $refTheme .'" />
			</td>
			<td style="width:30%;">
				描述：<input type="text" name="refDesc" size="20" style="width:175px;" value="'. $refDesc .'" />
			</td>
			<td style="width:40%;">
				电脑状态：<select id="refState" name="refState">
					<option value=""></option>
					<option value="1" '. Is::Selected($refState,1) .'>显示</option>
					<option value="0" '. Is::Selected($refState,0) .'>隐藏</option>
					</select>
				/&ensp;WAP状态：<select id="refWapState" name="refWapState">
					<option value=""></option>
					<option value="1" '. Is::Selected($refWapState,1) .'>显示</option>
					<option value="0" '. Is::Selected($refWapState,0) .'>隐藏</option>
					</select>
			</td>
		</tr>
		<tr>
			<td align="center" style="padding:5px;padding-top:20px" colspan="4">
				<input type="image" src="'. AdmTpl::ImgSrc('button_refer') .'" />
				&ensp;&ensp;&ensp;&ensp;
				<img src="'. AdmTpl::ImgSrc('button_reset') .'" onclick=\'document.location.href="?mudi='. $mudi .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'"\' style="cursor:pointer" alt="" />
			</td>
		</tr>
		</table>
		</form>
		');
	$skin->TableBottom();

	echo('
	<br />
	');
	*/

	echo('
	<form id="listForm" name="listForm" method="post" action="homePro_deal.php?mudi=moreDel" onsubmit="return CheckListForm()">
	<script language="javascript" type="text/javascript">document.write (\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'" />\')</script>
	<input type="hidden" name="dataType" value="'. $dataType .'" />
	<input type="hidden" name="dataTypeCN" value="'. $dataTypeCN .'" />
	');

	$skin->TableTop2('share_list.gif','',$dataTypeCN .'列表');
	$skin->TableItemTitle('4%,5%,16%,17%,5%,4%,11%,10%','<input type="checkbox" id="selAll" name="selAll" onclick="CheckBoxAll()" />,序号,'. $skin->ShowArrow('产品名称','HP_theme',$orderName,$orderSort) .',网址,价格左侧,'. $skin->ShowArrow('排序','HP_rank',$orderName,$orderSort) .','. $skin->ShowArrow('电脑','HP_state',$orderName,$orderSort) .'/'. $skin->ShowArrow('WAP状态','HP_wapState',$orderName,$orderSort) .',修改&ensp;删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit($SQLstr .' order by HP_'. $orderName .' '. $orderSort .'',$pageSize,$page);
	if (! $showRow){
		$skin->TableNoData();
	}else{
		$recordCount=$DB->GetRowCount();
		$pageCount=ceil($recordCount/$pageSize);
		if ($page < 1 || $page > $pageCount){$page=1;}

		echo('
		<tbody class="tabBody padd3td">
		');
		$number=1+($page-1)*$pageSize;
		$rowCount = count($showRow);
		for ($i=0; $i<$rowCount; $i++){
			if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }
			echo('
			<tr '. $bgcolor .' id="data'. $showRow[$i]['HP_ID'] .'">
				<td align="center" class="selCheckbox"><input type="checkbox" name="selDataID[]" value="'. $showRow[$i]['HP_ID'] .'" /></td>
				<td align="center">'. $number .'</td>
				<td align="left" style="word-break:break-all;">'. $showRow[$i]['HP_theme'] .'</td>
				<td align="center">'. $showRow[$i]['HP_url'] .'</td>
				<td align="center">'. $showRow[$i]['HP_price1'] .'</td>
				<td align="center">'. $showRow[$i]['HP_rank'] .'</td>
				<td align="center">
					'. Adm::SwitchBtn('homePro',$showRow[$i]['HP_ID'],$showRow[$i]['HP_state'],'state') .'/
					'. Adm::SwitchBtn('homePro',$showRow[$i]['HP_ID'],$showRow[$i]['HP_wapState'],'wapState','userState') .'
				</td>
				<td align="center">
					<img src="images/img_rev.gif" class="pointer" onclick=\'document.location.href="?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataID='. $showRow[$i]['HP_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" title="修改" />&ensp;&ensp;
					<img src="images/img_del.gif" class="pointer" onclick=\'if(confirm("你确定要删除？")==true){DataDeal.location.href="homePro_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['HP_theme']) .'&dataID='. $showRow[$i]['HP_ID'] .'"}\' alt="删除" title="删除" />
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		<tr class="tabColorB padd5">
			<td align="left" colspan="20">
				<input type="button" value="全选" onclick="AllSelBox()" class="form_button1" />
				<input type="button" value="反选" onclick="RevSelBox()" class="form_button1" />
				&ensp;
				<input type="submit" value="批量删除" />
			</td>
		</tr>
		');
	}
	unset($showRow);

	echo('</form>');

	$skin->TableBottom2($pageCount, $pageSize, $recordCount);
}

?>